package util;

import java.io.*;
import java.util.Properties;

/**
 * 使用属性文件存放错误信息,定时任务读取并将内容加载到内存中(Map里面)
 * 或者使用struts的方式参见下例,
 * 使用[i]单例模式[i]获取ResourceBundle rb = ResourceBundle.getBundle("MessageResources",Locale.CHINA);
 * http://blog.csdn.net/li_tengfei/article/details/6098162
 */
public class message {

    //单例模式 http://blog.csdn.net/jason0539/article/details/23297037/
    //不允许被其他的对象实例化
    private message() {
    }

    private static Properties properties = null;

    private static final Object LOCK = new Object();

    public static Properties getInstance() {
        if (properties == null) {
            synchronized (LOCK) {
                if (properties == null) {
                    properties = new Properties();
                    InputStream inputStream = new message().getClass().getResourceAsStream("/message.properties");
                    try {
                        properties.load(inputStream);
                    } catch (IOException e) {
                        e.printStackTrace();//所有的log4j打印日志 log.error打印
                    } finally {
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
        return properties;
    }
}
